package org.msi.bayesiannetwork;

/**
 * <p>Represents the observation used in expression.</p>
 *
 * @author Jakub Narloch
 * @version 1.0
 */
public class Variable {

    /**
     * <p>Represents the variable name.</p>
     */
    private final String variableName;

    /**
     * <p>Represents the flag indicating if variable is primitive, false means it is negative.</p>
     */
    private final boolean primitive;

    /**
     * <p>Creates new instance of {@link Variable} class with given variable name and flag indicating of it is
     * primitive.</p>
     *
     * @param variableName the variable name
     * @param primitive    the flag indicating if the variable is primitive
     */
    public Variable(String variableName, boolean primitive) {

        this.variableName = variableName;
        this.primitive = primitive;
    }

    /**
     * <p>Retrieves the variable name.</p>
     *
     * @return the variable name
     */
    public String getVariableName() {
        return variableName;
    }

    /**
     * <p>Sets the flag indicating if variable is primitive.</p>
     *
     * @return the flag indicating if variable is primitive
     */
    public boolean isPrimitive() {
        return primitive;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Variable variable = (Variable) o;

        if (!variableName.equals(variable.variableName)) return false;

        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {

        return variableName.hashCode();
    }
}
